<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>About Schemaish &mdash; Schemaish v0.5.2 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
          URL_ROOT:    '',
          VERSION:     '0.5.2',
          COLLAPSE_MODINDEX: false,
          FILE_SUFFIX: '.html'
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="top" title="Schemaish v0.5.2 documentation" href="index.html" />
    <link rel="prev" title="Welcome to Schemaish&#8217;s documentation!" href="index.html" /> 


  <link media="screen" href="_static/css/screen.css" type="text/css" rel="stylesheet" />
  <link media="screen" href="_static/css/images.css" type="text/css" rel="stylesheet" />
  <link media="screen" href="_static/css/sIFR-screen.css" type="text/css" rel="stylesheet" />
  <link media="print" href="_static/css/sIFR-print.css" type="text/css" rel="stylesheet" />  
  <script type="text/javascript" src="_static/js/sifr.js" ></script>
  <script type="text/javascript" src="_static/js/sifr-config.js" ></script> 
  <script type="text/javascript" src="_static/js/sifr-debug.js" ></script> 

  </head>
  <body id="sphinx">
    <div id="wrapper">
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="index.html" title="Welcome to Schemaish&#8217;s documentation!"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Schemaish v0.5.2 documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div id="header">
      <div id="logo"><img src="_static/images/logo/ish.io.png" /></div>
      <div id="overview"><a href="http://ish.io/projects/show/schemaish">Overview</a></div>
    </div>

<div id="main">
    <div  class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  
  <div class="section" id="about-schemaish">
<h1>About Schemaish<a class="headerlink" href="#about-schemaish" title="Permalink to this headline">¶</a></h1>
<p>Schemaish is a schema library that was initially written to support the formish form library. However it has been designed to work as a standalone schema package with validation from validatish.</p>
<div class="section" id="how-does-schemaish-work">
<h2>How does Schemaish work?<a class="headerlink" href="#how-does-schemaish-work" title="Permalink to this headline">¶</a></h2>
<p>There are two ways of creating schemas, the procedural way and the declarative way. Here is the procedural way.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">schemaish</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">schema</span> <span class="o">=</span> <span class="n">schemaish</span><span class="o">.</span><span class="n">Integer</span><span class="p">(</span><span class="n">title</span><span class="o">=</span><span class="s">&#39;My Integer&#39;</span><span class="p">,</span> <span class="n">description</span><span class="o">=</span><span class="s">&#39;This is really my integer&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>The schema can now be used to validate a value..</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">schema</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="mf">10</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Validation does not validate types, it only calls the validation that has been applied to the schema. If you need to have type validation, add a specific validator</p>
</div>
</div>
<div class="section" id="a-schemaish-structure">
<h2>A Schemaish Structure<a class="headerlink" href="#a-schemaish-structure" title="Permalink to this headline">¶</a></h2>
<p>Just create a create a structure and add schema attributes to it!</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">schema</span> <span class="o">=</span> <span class="n">schemaish</span><span class="o">.</span><span class="n">Structure</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">schema</span><span class="o">.</span><span class="n">add</span><span class="p">(</span> <span class="s">&#39;myfield&#39;</span><span class="p">,</span> <span class="n">schemaish</span><span class="o">.</span><span class="n">Integer</span><span class="p">()</span> <span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">schema</span><span class="o">.</span><span class="n">add</span><span class="p">(</span> <span class="s">&#39;myotherfield&#39;</span><span class="p">,</span> <span class="n">schemaish</span><span class="o">.</span><span class="n">String</span><span class="p">()</span> <span class="p">)</span>
</pre></div>
</div>
<p>and we can now validate a dictionary</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="n">schema</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span> <span class="p">{</span><span class="s">&#39;myfield&#39;</span><span class="p">:</span> <span class="mf">12</span><span class="p">,</span> <span class="s">&#39;myotherfield&#39;</span><span class="p">:</span> <span class="s">&#39;foo&#39;</span><span class="p">}</span> <span class="p">)</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The title and description are used by Formish as the label and description of each field.</p>
</div>
</div>
<div class="section" id="validation">
<h2>Validation<a class="headerlink" href="#validation" title="Permalink to this headline">¶</a></h2>
<p>See the validatish module documentation to learn more about the validators available.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">validatish</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">schema</span> <span class="o">=</span> <span class="n">schemaish</span><span class="o">.</span><span class="n">Integer</span><span class="p">(</span><span class="n">validator</span><span class="o">=</span><span class="n">validatish</span><span class="o">.</span><span class="n">Required</span><span class="p">())</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">schema</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="bp">None</span><span class="p">)</span>
<span class="go">...schemaish.attr.Invalid: is required</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">schema</span><span class="o">.</span><span class="n">validate</span><span class="p">(</span><span class="mf">10</span><span class="p">)</span>
</pre></div>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference" href="">About Schemaish</a><ul>
<li><a class="reference" href="#how-does-schemaish-work">How does Schemaish work?</a></li>
<li><a class="reference" href="#a-schemaish-structure">A Schemaish Structure</a></li>
<li><a class="reference" href="#validation">Validation</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="index.html" title="previous chapter">Welcome to Schemaish&#8217;s documentation!</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="_sources/introduction.txt">Show Source</a></li>
            </ul>
          <h3>Quick search</h3>
            <form class="search" action="search.html" method="get">
              <input type="text" name="q" size="18" /> <input type="submit" value="Go" />
              <input type="hidden" name="check_keywords" value="yes" />
              <input type="hidden" name="area" value="default" />
            </form>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="index.html" title="Welcome to Schemaish&#8217;s documentation!"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">Schemaish v0.5.2 documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2008, Tim Parkin, Matt Goodall.
    </div>
  </div> 
  </div>
  </body>
</html>